package com.wry.cloud.controller;

import cn.hutool.json.JSON;
import com.theokanning.openai.completion.CompletionChoice;
import com.theokanning.openai.completion.CompletionRequest;
import com.theokanning.openai.service.OpenAiService;
import com.wry.cloud.service.OrderService;
import com.wry.cloud.utils.ApiResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * <h1>  </h1>
 *
 * @author <a href="mailto::15671496069@163.com">WeiRuYuan</a>
 * @since 2022/9/7
 */
@RestController
@RequestMapping("order")
public class OrderController {


    @Resource
    private OrderService orderService;

    @GetMapping("{id}")
    public ApiResult<?> order(@PathVariable Long id){
        return orderService.getPayment(id);
    }

    @GetMapping("zipkin")
    public String zipkin(){
        return orderService.zipkin();
    }

    @GetMapping("gpt")
    public ApiResult<String> gpt(){
        String key = "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";
        OpenAiService openAiService = new OpenAiService(key);
        CompletionRequest completionRequest = CompletionRequest.builder()
                .model("text-davinci-003")
                .prompt("今天天气怎么样？")
                .temperature(0.5)
                .maxTokens(2048)
                .topP(1D)
                .frequencyPenalty(0D)
                .presencePenalty(0D)
                .build();
        final List<CompletionChoice> choices = openAiService.createCompletion(completionRequest).getChoices();

        return new ApiResult<>(200, choices.toString());
    }
}
